import { createSlice } from '@reduxjs/toolkit'


export const userSlice = createSlice({
  name: 'user',
  initialState: {
    userInfo: { token: "" },
  },
  reducers: {
    changeUserInfo: (state: any, action) => {
      state.userInfo = action.payload
    },
    doLogout(state: any, action) {
      state.userInfo = {};
    },
    setToken(state,action){
      state.userInfo.token = action.payload;
      localStorage.setItem("token",action.payload)
    }
  }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { changeUserInfo,doLogout,setToken} = userSlice.actions

export default userSlice.reducer